package com.example.a2209_shop

import android.annotation.SuppressLint
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.webkit.WebChromeClient
import android.webkit.WebView
import android.webkit.WebViewClient
import androidx.core.view.isVisible
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.example.a2209_shop.databinding.ActivityWebView2Binding
import com.example.base.mvvm.BaseViewActivity

@Route(path = "/app/WebViewActivity2")
class WebViewActivity2 : BaseViewActivity<ActivityWebView2Binding>() {
    @Autowired
    @JvmField
    var url=""
    override fun initData() {

    }

    override fun initView() {
        ARouter.getInstance().inject(this)
        binding.wv.loadUrl(url)
        binding.wv.webViewClient = WebViewClient()
        binding.wv.settings.javaScriptEnabled = true//允许和js进行交互
        binding.wv.webChromeClient = object :WebChromeClient(){
            //显示进度条
            override fun onProgressChanged(view: WebView?, newProgress: Int) {
                super.onProgressChanged(view, newProgress)
                if(newProgress==100){
                    binding.pb.isVisible = false
                }else{
                    binding.pb.progress = newProgress
                }
            }
        }
    }

    override fun getLayout(): Int  = R.layout.activity_web_view2


}